package serverAndThreads;

import gui.Contact;
import gui.GroupPanel;
import gui.MainFrame;
import Projektarbete.Group;
import Projektarbete.User;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.ArrayList;

import javax.swing.JPanel;

public abstract class CT {

	public abstract void perform(MainFrame mf, ObjectInputStream in,
			ObjectOutputStream out, Socket socket) throws IOException,
			ClassNotFoundException;

	public static class AddContact extends CT {

		@Override
		public void perform(MainFrame mf, ObjectInputStream in,
				ObjectOutputStream out, Socket socket) throws IOException,
				ClassNotFoundException {

			User user = (User) in.readObject();
			mf.addSingleContact(user);

		}

	}

	public static class UpdateOnlineStatus extends CT {
		
		public void perform(MainFrame mf, ObjectInputStream in,
				ObjectOutputStream out, Socket socket) throws IOException,
				ClassNotFoundException {
			
			User user = (User) in.readObject();
			mf.updateOnlineStatus(user);

		}
	}
	
	public static class RemoveContact extends CT{

		@Override
		public void perform(MainFrame mf, ObjectInputStream in,
				ObjectOutputStream out, Socket socket) throws IOException,
				ClassNotFoundException {
				
			User user = (User) in.readObject();
			mf.removeSingleContact(user);
			
		}
		
	}
	
	public static class AddGroup extends CT{

		@Override
		public void perform(MainFrame mf, ObjectInputStream in,
				ObjectOutputStream out, Socket socket) throws IOException,
				ClassNotFoundException {
			
			Group group = (Group) in.readObject();
			mf.addToGroup(group);
			
		}
		
	}
	
	public static class RemoveGroup extends CT{

		@Override
		public void perform(MainFrame mf, ObjectInputStream in,
				ObjectOutputStream out, Socket socket) throws IOException,
				ClassNotFoundException {
			
			Group group = (Group) in.readObject();
			mf.removeFromGroup(group);
			
		}
		
	}
	
	public static class UpdateGroup extends CT{

		@Override
		public void perform(MainFrame mf, ObjectInputStream in,
				ObjectOutputStream out, Socket socket) throws IOException,
				ClassNotFoundException {
			
			Group group = (Group) in.readObject();
			mf.updateGroup(group);
			
		}
		
	}
}
